import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

export const useShopStore = defineStore('shop', () => {
  // 店铺信息状态
  const id = ref(null)
  const loading = ref(false)
  const error = ref(null)

  // 获取店铺ID
  const shopId = computed(() => {
    return id.value || null
  })
  
  // 设置店铺ID
  const setShopId = (id) => {
    id.value = id
  }

  // 清除店铺ID
  const clearShopId = () => {
    id.value = null
    error.value = null
  }

  // 设置加载状态
  const setLoading = (isLoading) => {
    loading.value = isLoading
  }

  // 设置错误信息
const setError = (err) => {
  error.value = err
}

  return {
    // 状态
    id,
    loading,
    error,
    
    // 计算属性
    shopId,
    
    // 方法
    setShopId,  
    clearShopId,
    setLoading,
    setError
  }
})